//
//  WorkflowListCell.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 2017/8/30.
//  Copyright © 2017年 com.xtion.crm. All rights reserved.
//

#import "WorkflowListCell.h"

#define HeadImageSize       45
#define BorderLeftRightMargin        10
#define ControlLeftRightMargin          10
#define ControlTopBottomMargin          10

@interface WorkflowListCell()
{
    UILabel *_processNameLabel;
    UILabel *_processStateLabel;
    UILabel *_appNameLabel;
    UILabel *_createdUserDeptLabel;
    UILabel *_createdDateTimeLabel;
    
    UIView *_titleView;
    UIView *_backView;
}
@end

@implementation WorkflowListCell

-(id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    self.backgroundColor = [UIColor colorWithHex:mcrmSAASUISkinColorTextStylef1f4f7Color];
    
    _titleView = [[UIView alloc] initWithFrame:CGRectMake(BorderLeftRightMargin, 0, 0, 0)];
    _titleView.backgroundColor = [UIColor colorWithHex:mcrmSAASUIShinColorTextStylee91E63Color];
    [self.contentView addSubview:_titleView];
    
    _backView = [[UIView alloc] initWithFrame:CGRectMake(BorderLeftRightMargin, 0, 0, 0)];
    _backView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_backView];
    
    CGSize s = [NSString charSizeWithSystemFontSize:13];
    _processNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*10, s.height)];
    _processNameLabel.backgroundColor = [UIColor clearColor];
    _processNameLabel.font = [UIFont systemFontOfSize:13];
    [_titleView addSubview:_processNameLabel];
    
    s = [NSString charSizeWithSystemFontSize:13];
    _processStateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*5, s.height)];
    _processStateLabel.backgroundColor = [UIColor clearColor];
    _processStateLabel.font = [UIFont systemFontOfSize:13];
    _processStateLabel.textAlignment = NSTextAlignmentRight;
    [_titleView addSubview:_processStateLabel];
    
    s = [NSString charSizeWithSystemFontSize:16];
    _appNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*20, s.height)];
    _appNameLabel.backgroundColor = [UIColor clearColor];
    _appNameLabel.font = [UIFont systemFontOfSize:16];
    [_backView addSubview:_appNameLabel];
    
    s = [NSString charSizeWithSystemFontSize:10];
    _createdUserDeptLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*20, s.height)];
    _createdUserDeptLabel.backgroundColor = [UIColor clearColor];
    _createdUserDeptLabel.font = [UIFont systemFontOfSize:10];
    [_backView addSubview:_createdUserDeptLabel];
    
    s = [NSString charSizeWithSystemFontSize:10];
    _createdDateTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, s.width*10, s.height)];
    _createdDateTimeLabel.backgroundColor = [UIColor clearColor];
    _createdDateTimeLabel.font = [UIFont systemFontOfSize:10];
    [_backView addSubview:_createdDateTimeLabel];
  
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _titleView.width = self.contentView.width - BorderLeftRightMargin*2;
    _titleView.height = _processNameLabel.height + 2*BorderLeftRightMargin;
    
    _backView.top = _titleView.bottom;
    _backView.width = self.contentView.width - BorderLeftRightMargin*2;
    _backView.height = self.contentView.height -_titleView.height - BorderLeftRightMargin;
    
    _processNameLabel.left = BorderLeftRightMargin;
    _processNameLabel.top = BorderLeftRightMargin;
    
    _processStateLabel.right = _backView.width - BorderLeftRightMargin;
    _processStateLabel.top = _processNameLabel.top;
    
    _appNameLabel.left = BorderLeftRightMargin;
    _appNameLabel.top = ControlTopBottomMargin;
    _appNameLabel.width = _backView.width - BorderLeftRightMargin*2;
    
    _createdUserDeptLabel.left = BorderLeftRightMargin;
    _createdUserDeptLabel.top = _appNameLabel.bottom + ControlTopBottomMargin;
    
    _createdDateTimeLabel.right = _backView.width - BorderLeftRightMargin;
    _createdDateTimeLabel.top = _createdUserDeptLabel.top;
}

-(void)setTitleViewColor:(UIColor*)color
{
    _titleView.backgroundColor = color;
}

-(NSString*)setProcessStatus:(NSInteger)processStatus
{
    NSString *status = @"未知";
    if(processStatus == 2)
    {
        status = @"运行中";
        _titleView.backgroundColor = [UIColor colorWithHex:mcrmSAASUIShinColorTextStylee91E63Color];
    }
    if(processStatus == 4)
    {
        status = @"已完成";
        _titleView.backgroundColor = [UIColor greenColor];
    }
    if(processStatus == 7)
    {
        status = @"终止";
        _titleView.backgroundColor = [UIColor grayColor];
    }
    return status;
}

+(CGFloat)caleHeight:(CGFloat)containWidth content:(NSString*)content;
{
    CGFloat height = 0 ;
    
    height = BorderLeftRightMargin;
    CGSize s = [NSString charSizeWithSystemFontSize:13];
    height += s.height;
    height += ControlTopBottomMargin;
    
    height += ControlTopBottomMargin;
    CGFloat width = containWidth - BorderLeftRightMargin - BorderLeftRightMargin;
    height += [content wrapStringSizeWithFont:[UIFont systemFontOfSize:16] forWidth:width].height;
    height += ControlTopBottomMargin;
    
    height += ControlTopBottomMargin;
    s = [NSString charSizeWithSystemFontSize:10];
    height += s.height;
    height += ControlTopBottomMargin;
    
    height += 0.5*2;
    
    return height;
}

-(void)setProcessName:(NSString *)processName
{
    _processNameLabel.text = processName;
}

-(void)setProcessState:(NSString *)processState
{
    _processStateLabel.text = processState;
}

-(void)setAppName:(NSString *)appName
{
    _appNameLabel.text = appName;
}

-(void)setCreatedUserDept:(NSString *)createdUserDept
{
    _createdUserDeptLabel.text = createdUserDept;
}

-(void)setCreatedDateTime:(NSDate *)createdDateTime
{
    _createdDateTimeLabel.text = [createdDateTime toStringDate:yMdHms];
}

@end

@implementation AttendanceRecordCalcuteInfo

@end

@implementation WorkflowCellList

-(id)init
{
    self = [super init];
    
    self.rowHeight = CaleRowHeightTag;
    
    return self;
}

+(NSArray*)workflowListToListArray:(NSArray*)data
{
    NSMutableArray *ar = [NSMutableArray new];
    
    //日历头部
    {
        WorkflowCellList *rec = [WorkflowCellList new];
        rec.type = WorkflowListTypeDateType;
        [ar addObject:rec];
    }
    //日历
    {
        WorkflowCellList *rec = [WorkflowCellList new];
        rec.type = WorkflowListTypeCalendarType;
        rec.curDate = [NSDate new];
        rec.datas = data;
        [ar addObject:rec];
    }
    //列表
    for (NSInteger i = 0; i < data.count; i++)
    {
        WorkflowCellList *rec = [WorkflowCellList new];
        rec.type = WorkflowListTypeContent;
        rec.wf = data[i];
        [ar addObject:rec];
    }
    
    return ar;
}
@end
